package com.bgs.controller;


import com.bgs.common.R;
import com.bgs.service.BeforeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.bgs.pojo.BeforeUser;
import org.springframework.web.bind.annotation.*;
import com.bgs.common.R;
import com.bgs.service.BeforeUserService;
import com.bgs.service.TokenUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前台用户表 前端控制器
 * </p>
 *
 * @author Asia
 * @since 2021-09-14
 */
@RestController
@RequestMapping("/bgs/before-user")
public class BeforeUserController {
    //依赖注入
    @Resource
    private BeforeUserService beforeUserService;
    @Resource
    private TokenUserService tokenUserService;

    @GetMapping("zeroReturnGoodsSubtractBalance/{beforeUserId}/{returnGoodsPayment}")
    public boolean zeroReturnGoodsSubtractBalance(@PathVariable("beforeUserId") Integer beforeUserId, @PathVariable("returnGoodsPayment") Double returnGoodsPayment) {
        return beforeUserService.zeroReturnGoodsSubtractBalance(beforeUserId, returnGoodsPayment);
    }

    @GetMapping("zeroBeforeUserIdToBeforeUser/{beforeUserId}")
    public List<BeforeUser> zeroBeforeUserIdToBeforeUser(@PathVariable("beforeUserId") Integer beforeUserId) {
        return beforeUserService.zeroBeforeUserIdToBeforeUser(beforeUserId);
    }

    //对用户进行违规封禁，状态为2
    @GetMapping("zeroBeforeUserDelete2")
    public R zeroBeforeUserDelete2(Integer beforeUserId){
        return beforeUserService.zeroBeforeUserDelete2(beforeUserId);
    }
    //根据违规店铺查询到该商户
    @GetMapping("zeroFindBeforeUserByBeforeUserId")
    public R zeroFindBeforeUserByBeforeUserId(Integer beforeUserId){
        return beforeUserService.zeroFindBeforeUserByBeforeUserId(beforeUserId);
    }


    /**
     * 查询所有用户
     *
     * @return
     */
    @PostMapping("/user/fourQueryAll")
    public R fourQueryAll(@RequestBody BeforeUser beforeUser){
        return beforeUserService.fourQueryAll(beforeUser);
    }

    @PostMapping("/user/fourEditUser")
    public R fourEditUser(@RequestBody BeforeUser beforeUser){
        System.out.println(beforeUser.toString());
        return beforeUserService.fourEditUser(beforeUser);
    }


    @GetMapping("/ThreeSend")
    @ApiOperation("用户注册发送邮箱")
    public R ThreeSend(String email){
        return beforeUserService.ThreeSend(email);
    }
    @GetMapping("/ThreeZhuCe")
    @ApiOperation("用户注册")
    public R ThreeZhuCe(String email,String code){
        return beforeUserService.ThreeZhuCe(email,code);
    }
    @PostMapping("/ThreeAddUser")
    @ApiOperation("完善信息")
    public R ThreeAddUser(@RequestBody BeforeUser beforeUser){
        return beforeUserService.ThreeAddUser(beforeUser);
    }

    @GetMapping("/ThreeBeforeLogin")
    @ApiOperation("前端登录，返回token")
    public R ThreeBeforeLogin(String beforeUserName, String beforePassword) {
        return tokenUserService.ThreeBeforeLogin(beforeUserName, beforePassword);
    }

    @GetMapping("/ThreeLogout")
    @ApiOperation("登出方法-清除Token")
    public R ThreeLogout() {
        return tokenUserService.ThreeLogout();
    }

    @GetMapping("/ThreeFindId")
    public R ThreeFindId(String beforeUserId) {
        return beforeUserService.ThreeFindId(beforeUserId);
    }

    /**
     * 查看用户余额
     * @param beforeUserId
     * @return
     */
    @GetMapping("/TowBalance")
    public R TowBalance(Integer beforeUserId){
        BeforeUser data = beforeUserService.TowBalance(beforeUserId);
        return R.ok().data("beforeUser",data);
    }
}

